import { defineStore } from "pinia";
import {login} from '@/api'
import { IuserState } from "@/types/uer.type";
export const useUserStore = defineStore({
  id: "user", // id必填，且需要唯一
  state: () => {
    return {
      name: "张三",
      token: ''
    };
  },
  actions: {
    updateName(name: string) {
      this.name = name;
    },
    async login(userData: IuserState){
      const {user_name,token} = await login(userData)
      console.log(user_name,token)
    }
  },
  // 开启数据缓存 默认存储在sessionStorage
  persist: {
    enabled: true,
    strategies: [
      {
        key: "my_user",
        storage: localStorage,
        paths: ["name","token"], // 需要持久化的项目，不配置全部持久化
      },
    ],
  },
});
